package com.zhixiang.core.web.filter;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class ResponseHeaderFilter
  implements Filter
{
  private FilterConfig fc;

  public void doFilter(ServletRequest paramServletRequest, ServletResponse paramServletResponse, FilterChain paramFilterChain)
    throws IOException, ServletException
  {      
    	    HttpServletResponse localHttpServletResponse = (HttpServletResponse)paramServletResponse;
    	    Enumeration<String> localEnumeration = this.fc.getInitParameterNames();
    	    while (localEnumeration.hasMoreElements()) {
    	      String str = (String)localEnumeration.nextElement();
    	      localHttpServletResponse.addHeader(str, 
    	        this.fc.getInitParameter(str));
    	    }
    	    paramFilterChain
    	      .doFilter(paramServletRequest, localHttpServletResponse);    
  }

  public void init(FilterConfig paramFilterConfig) {
    this.fc = paramFilterConfig;
    /*Timer timer = new Timer();
    timer.schedule(new TimerTask()
    {
      public void run() {
        Boolean is_true = AppUtil.getStart();
        if (!is_true.booleanValue()) {
          ResponseHeaderFilter.logger.error("未检查到授权或授权已经过期....");
          ResponseHeaderFilter.logger.error("服务停止，请尽快购买授权....");
          System.exit(0);
        } else {
          ResponseHeaderFilter.logger.info("检查授权成功....");
        }
      }
    }
    , 30000L);*/
  }

  public void destroy() {
    this.fc = null;
  }
}

